import Mock from 'mockjs'

const RoomList = []
const count = 5

const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'

for (let i = 0; i < count; i++) {
  RoomList.push(Mock.mock({
    roomId: '@integer(1, 3)',
    roomCode: 'HYS-@increment(0)',
    name: '会议室@increment(1)',
    main_pic: image_uri,
    area: '@cword(5, 10)',
    position: '@cword(5, 10)',
    seating: '@integer(1, 300)',
    contacts: '@cname(2, 4)',
    contactsPhone: '@integer(11)',
    'isEnabled|1': [true, false],
    'status|1-2': 1,
    remarks: '@csentence'
  }))
}

export default [
  {
    url: '/v1/meeting/meetingRoom/queryMeetingRoomList',
    type: 'post',
    response: config => {
      const { importance, type, title, page = 1, limit = 20, sort } = config.query

      let mockList = RoomList.filter(item => {
        if (importance && item.importance !== +importance) return false
        if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }

      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return {
        code: 1,
        mesg: 'success',
        time: Mock.Random.date('T'),
        data: {
          totalCount: mockList.length,
          meetingRoomList: pageList,
          limit: 10,
          page: 1
        }
      }
    }
  }
]

